package xyz.xuminghai.javafx_learn.animation.transition;

import javafx.animation.TranslateTransition;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import javafx.util.Duration;

/**
 * 2023/7/30 7:41 星期日<br/>
 * 此Transition创建一个跨越其duration移动/平移动画。这是通过定期更新node的translateX 、
 * translateY和translateZ变量来完成的。
 *
 * @author xuMingHai
 */
public class TranslateTransitionApp extends Application {

    private final BorderPane root = new BorderPane();

    public static void main(String[] args) {
        Application.launch(args);
    }


    @Override
    public void init() {
        Rectangle rectangle = new Rectangle(100.0, 100.0);

        TranslateTransition translateTransition = new TranslateTransition(Duration.millis(3000.0),
                rectangle);
        translateTransition.setToX(200.0);
        translateTransition.setToY(100.0);
        translateTransition.play();

        root.setCenter(rectangle);
    }


    public void start(Stage primaryStage) {
        primaryStage.setTitle(getClass().getSimpleName());
        Scene scene = new Scene(root, 800, 600);
        primaryStage.setScene(scene);
        primaryStage.show();
    }

}
